package com.shiwaixiangcun.customer.module.property

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.shiwaixiangcun.customer.R
import com.shiwaixiangcun.customer.entity.PropertyPaymentDetailEntity
import com.shiwaixiangcun.customer.utils.DateUtil
import kotlinx.android.synthetic.main.fragment_one_property.*

private const val ARG_PARAM1 = "param1"

/**
 * 1套房产情况
 */
class OnePropertyFragment : Fragment() {
    private var param1: PropertyPaymentDetailEntity? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getParcelable(ARG_PARAM1)
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_one_property, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initViewAndEvent()
    }

    @SuppressLint("SetTextI18n")
    private fun initViewAndEvent() {
        if (!param1?.isSupport!!) {
            tv_no_payment.visibility = View.GONE
            tv_next_time.text = "暂不支持网上缴费"
            tv_house_name.text = param1?.house
            tv_property_name.text = param1?.property
        } else if (!param1?.isExistBill!!) {
            tv_no_payment.text = "账单暂未生成"
            tv_no_payment.visibility = View.VISIBLE
            tv_next_time.text = "下期账单将于 ${DateUtil.getCustomFormat(param1?.nextStatementDate?.toLong()!!, "yyyy-MM-dd")}生成"
            tv_house_name.text = param1?.house
            tv_property_name.text = param1?.property
        }

    }


    companion object {

        @JvmStatic
        fun newInstance(param1: PropertyPaymentDetailEntity) =
                OnePropertyFragment().apply {
                    arguments = Bundle().apply {
                        putParcelable(ARG_PARAM1, param1)
                    }
                }
    }
}
